<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/demo',function(){
//    $order_no = request()->get('online_order');
//    $service = new \App\Services\ReportService($order_no,\App\Services\ReportService::RequestCodeRefund);
//    \App\Jobs\HtReportApi::dispatch($service);
    try{
        $data = \Illuminate\Support\Facades\DB::table('order')
            ->where('order_type',\App\Models\Order::TYPE_ONLINE)
            ->where('send_type',\App\Models\Order::POST)
            ->where('status',\App\Models\Order::STATUS_WAIT_COLLECT)
            ->where('send_time','<',\Carbon\Carbon::now()->subDays(3)->toDateTimeString())
            ->whereNotNull('express_order')
            ->select('id','online_order','express_name','express_order')
            ->orderBy('id','asc')
            ->chunk(10,function($collections){
                dispatch(new \App\Jobs\AutoCompleteOrder($collections));
                if(\Illuminate\Support\Facades\App::environment('local')){
                    \Illuminate\Support\Facades\Log::channel('express_dispatch')->info('插入队列成功', ['data' => $collections]);
                }
            });
    }catch (\Exception $exception){dd($exception);
        \Illuminate\Support\Facades\Log::channel('express_dispatch')->info($exception->getMessage());
    }
});

Route::get('/', function () {
    return redirect('/admin/index');
});

Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () {
    Route::get('login', 'LoginController@login');
    Route::post('login','LoginController@loginPost')->name('login.post');
    Route::get('error', 'MainController@error')->name('error');
    Route::get('showerror', 'MainController@showerror')->name('showerror');
    Route::get('logout', 'LoginController@logout')->name('admin.logout');
});

Route::group(['middleware' => ['login.check'] , 'prefix' => 'admin', 'namespace' => 'Admin'], function () {
    Route::get('updatepwd', 'LoginController@updatepwd');
    //后台布局
    Route::get('index', 'MainController@index')->name('admin.index');
    Route::get('main','MainController@main')->name('admin.main');

    Route::group(['prefix' => 'adminer'], function () {
        Route::get('/', 'AdminerController@index')->name('adminer.data');

        Route::any('add', 'AdminerController@add')->name('adminer.add');

        Route::get('{id}/edit', 'AdminerController@edit')->name('adminer.edit');
        Route::put('{id}', 'AdminerController@edit')->name('adminer.update');

        Route::delete('{id}', 'AdminerController@delete')->name('adminer.destroy');

        Route::get('profile', 'AdminerController@profile')->name('adminer.profile');
        Route::any('updatepwd', 'AdminerController@updatepwd')->name('adminer.updatepwd');
        Route::post('upstatus/{id}', 'AdminerController@upstatus')->name('adminer.upstatus');

        Route::any('table', 'AdminerController@table')->name('adminer.table');
    });

    Route::group(['prefix' => 'role'], function () {
        Route::get('/', 'RoleController@index')->name('role.data');
        Route::any('add', 'RoleController@add')->name('role.add');
        Route::any('edit', 'RoleController@edit')->name('role.edit');
        Route::get('destroy', 'RoleController@destroy')->name('role.destroy');
    });

    Route::group(['prefix' => 'menu'], function () {
        Route::post('getMenuList', 'MenuController@getMenuList')->name('menu.getMenuList');
        Route::post('ismenu', 'MenuController@ismenu')->name('menu.ismenu');
        Route::post('status', 'MenuController@status')->name('menu.status');
    });
    Route::resource('menu','MenuController');

    //商品管理
    Route::group(['prefix' => 'goods'], function () {
        Route::get('{id?}/list', 'GoodsController@getGoodsList')->name('goods.list');//1销售中2下架3已售罄4价格查询
        Route::any('{id?}/table', 'GoodsController@table')->name('goods.table');//1销售中2已售罄3下架
        Route::get('add', 'GoodsController@add')->name('goods.add');
        Route::post('save', 'GoodsController@add')->name('goods.save');
        Route::post('delete', 'GoodsController@delete')->name('goods.delete');
        Route::get('{goods}/edit', 'GoodsController@edit')->name('goods.edit');
        Route::put('{goods}/edit', 'GoodsController@edit')->name('goods.update');
        Route::post('upsort', 'GoodsController@upsort')->name('goods.upsort');//更新sort

        Route::any('uploadPhoto', 'GoodsController@uploadPhoto')->name('goods.uploadphoto');//上传图片
        Route::any('uploadConfig', 'GoodsController@uploadConfig')->name('goods.uploadConfig');//上传配置图片
        Route::post('configdel', 'GoodsController@configdel')->name('goods.configdel');//删除配置
        Route::post('configchange', 'GoodsController@configchange')->name('goods.configchange');//更新产品基本信息name字段
        Route::any('{id?}/uploadpage', 'GoodsController@uploadPage')->name('goods.uploadPage');//上传配置图片页面(弹出框)
        Route::any('{id?}/setStatus', 'GoodsController@setStatus')->name('goods.setStatus');//上下架 1下架 3上架

        Route::get('config', 'GoodsController@config')->name("goods.config");//商品基本信息管理
        Route::any('config', 'GoodsController@config')->name("goods.configsave");//商品基本信息管理
        Route::get('buyset', 'GoodsController@buyset')->name("goods.buyset");//商品购买配置
        Route::put('buyset', 'GoodsController@buyset')->name("goods.buysetsave");//商品购买配置
        Route::post('export', 'GoodsController@export')->name("goods.export");//商品导出
    });
    //库存管理
    Route::group(['prefix' => 'store'], function () {
        Route::get('getList', 'StoreController@getList')->name('store.getList');//在售库存表
        Route::any('tabelList', 'StoreController@tabelList')->name('store.tabelList');//在售库存表数据
        Route::get('padList', 'StoreController@padList')->name('store.padList'); //补货
        Route::get('padListTabel', 'StoreController@padListTabel')->name('store.padListTabel'); //补货数据
        Route::get('{data?}/doPad', 'StoreController@doPad')->name('store.doPad');//确认补货框
        Route::post('savePad', 'StoreController@savePad')->name('store.savePad');//确认补货
        Route::any('orderno', 'StoreController@orderno')->name('store.orderno');//ajax 验证补货单号唯一性
        Route::get('padRecord', 'StoreController@padRecord')->name('store.padRecord');//补货记录
        Route::any('export', 'StoreController@export')->name('store.export');//补货记录导出
        Route::any('exportdetail', 'StoreController@exportdetail')->name('store.exportdetail');//补货记录详情导出
        Route::get('{id?}/padRecordDetail', 'StoreController@padRecordDetail')->name('store.padRecordDetail');//补货记录详情
        Route::post('{id?}/padRecordDetailTable', 'StoreController@padRecordDetailTable')->name('store.padRecordDetailTable');//补货记录详情数据
        Route::post('padRecordTable', 'StoreController@padRecordTable')->name('store.padRecordTable');//补货记录数据
        Route::post('{id?}/padRecordTableById', 'StoreController@padRecordTableById')->name('store.padRecordTableById');//补货记录数据根据id
    });
    //订单管理
    Route::group(['prefix' => 'order'], function () {
        //订单表 1代付款 2代发货 3待收货 4待取货 5完成 6售后 7已取消 8已退款 0全部订单
        Route::get('{id?}/getList', 'OrderController@getList')->name('order.getList');
        Route::post('{id?}/table', 'OrderController@table')->name('order.table');//订单表数据
        Route::get('{id?}/detail', 'OrderController@detail')->name('order.detail');//订单详情
        Route::get('export', 'OrderController@export')->name('order.export'); //导出
        Route::get('{id?}/deliver', 'OrderController@deliver')->name('order.deliver'); //发货弹出框
        Route::post('deliverSave', 'OrderController@deliverSave')->name('order.deliverSave'); //设置发货
        Route::post('refund', 'OrderController@refund')->name('order.refund'); //设置退款
        Route::post('reject', 'OrderController@reject')->name('order.reject'); //设置驳回
        Route::post('export', 'OrderController@export')->name('order.export'); //导出

    });
    //邮寄管理
    Route::group(['prefix' => 'post'], function () {
        Route::get('getList', 'PostController@getList')->name('post.getList');
        Route::post('table', 'PostController@table')->name('post.table');
        Route::get('{post?}/detail', 'PostController@detail')->name('post.detail');
        Route::get('config', 'PostController@config')->name('post.config');//
        Route::put('configSave', 'PostController@configSave')->name('post.configSave');//
    });


    //加盟合伙人
    Route::group(['prefix' => 'partner'], function () {
        Route::get('index', 'PartnerController@index')->name('partner.index');
        Route::post('table', 'PartnerController@table')->name('partner.table');
        Route::any('export', 'PartnerController@export')->name('partner.export');
    });

    /* 队列通知消息 */
    Route::group(['prefix' => 'exportLogs'], function () {
        Route::any('table', 'ExportLogsController@table')->name('exportLogs.table');
        Route::get('download/{id}', 'ExportLogsController@download')->where(['id' => '[0-9]+'])->name('exportLogs.download');
    });
    Route::resource('exportLogs', 'ExportLogsController');

    //会员管理
    Route::group(['prefix' => 'user'], function () {
        Route::get('index', 'UserController@index')->name('user.index');
        Route::post('table', 'UserController@table')->name('user.table');
        Route::get('show/{id}', 'UserController@show')->name('user.show');
        Route::any('inviteList/{id}', 'UserController@inviteList')->name('user.invitelist');
        Route::any('changeInvite/{id}', 'UserController@changeInvite')->name('user.changeinvite');
        Route::any('moneyRecharge/{id}', 'UserController@moneyRecharge')->name('user.moneyrecharge');
        Route::any('moneyEightConsh/{id}', 'UserController@moneyEightConsh')->name('user.moneyeightconsh');
        Route::any('moneyConsh/{id}', 'UserController@moneyConsh')->name('user.moneyconsh');
        Route::any('orderList/{id}', 'UserController@orderList')->name('user.orderlist');
        Route::any('export', 'UserController@export')->name('user.export');

        //会员等级设置
        Route::any('levelSet', 'UserController@levelSet')->name('user.levelset');
        Route::any('levelSetTable', 'UserController@levelSetTable')->name('user.levelsettable');

        //会员邀请查询
        Route::any('userInvit/{id?}', 'UserController@userInvit')->name('user.userinvit');

        Route::any('orderList/{id?}', 'UserController@orderList')->name('user.orderlist');
    });


    //员工列表管理
    Route::group(['prefix' => 'staff'], function () {
        Route::get('index', 'StaffController@index')->name('staff.index');
        Route::post('table', 'StaffController@table')->name('staff.table');

        Route::get('add', 'StaffController@create')->name('staff.add');
        Route::post('store', 'StaffController@store')->name('staff.store');

        Route::get('edit/{id?}', 'StaffController@edit')->name('staff.edit');
        Route::put('update', 'StaffController@update')->name('staff.update');

        Route::get('show/{id?}', 'StaffController@show')->name('staff.show');
        Route::any('registerUser/{id?}', 'StaffController@registerUser')->name('staff.registeruser');
        Route::any('recharge/{id?}', 'StaffController@recharge')->name('staff.recharge');
        Route::any('orderList/{id?}', 'StaffController@orderList')->name('staff.orderlist');
    });

    //部门管理
    Route::group(['prefix' => 'department'], function () {
        Route::any('index', 'DepartmentController@index')->name('department.index');

        Route::get('add', 'DepartmentController@create')->name('department.add');
        Route::post('store', 'DepartmentController@store')->name('department.store');
        Route::delete('destroy/{id?}', 'DepartmentController@destroy')->name('department.destroy');

    });

    //职位管理
    Route::group(['prefix' => 'position'], function () {
        Route::any('index', 'PositionController@index')->name('position.index');

        Route::any('add', 'PositionController@create')->name('position.add');
        Route::post('store', 'PositionController@store')->name('position.store');
        Route::delete('destroy/{id?}', 'PositionController@destroy')->name('position.destroy');
    });

    //满减活动
    Route::group(['prefix' => 'offer'], function () {
        Route::any('index', 'OfferController@index')->name('offer.index');
        Route::post('table', 'OfferController@table')->name('offer.table');
        Route::get('edit/{id}', 'OfferController@edit')->name('offer.edit');
        Route::put('edit/{id}', 'OfferController@update')->name('offer.update');
        Route::any('add', 'OfferController@create')->name('offer.add');
        Route::post('store', 'OfferController@store')->name('offer.store');
        Route::post('upstatus/{id?}', 'OfferController@upstatus')->name('offer.upstatus');
        Route::delete('destroy/{id?}', 'OfferController@destroy')->name('offer.destroy');
    });
    //优惠券
    Route::group(['prefix' => 'coupon'], function () {
        Route::any('index', 'CouponController@index')->name('coupon.index');
        Route::post('table', 'CouponController@table')->name('coupon.table');
        Route::get('edit/{id}', 'CouponController@edit')->name('coupon.edit');
        Route::put('edit/{id}', 'CouponController@update')->name('coupon.update');
        Route::any('add', 'CouponController@create')->name('coupon.add');
        Route::post('store', 'CouponController@store')->name('coupon.store');
    });
    //优惠券发放
    Route::group(['prefix' => 'marketing'], function () {
        Route::any('index', 'MarketingController@index')->name('marketing.index');
        Route::post('table', 'MarketingController@table')->name('marketing.table');
        Route::any('add', 'MarketingController@create')->name('marketing.add');
        Route::post('store', 'MarketingController@store')->name('marketing.store');
    });
    //活动
    Route::group(['prefix' => 'activity'], function () {
        Route::any('index', 'ActivityController@index')->name('activity.index');
        Route::post('table', 'ActivityController@table')->name('activity.table');
        Route::get('edit/{id}', 'ActivityController@edit')->name('activity.edit');
        Route::put('edit/{id}', 'ActivityController@update')->name('activity.update');
        Route::any('add', 'ActivityController@create')->name('activity.add');
        Route::post('store', 'ActivityController@store')->name('activity.store');
        Route::post('upstatus/{id?}', 'ActivityController@upstatus')->name('activity.upstatus');
        Route::delete('destroy/{id?}', 'ActivityController@destroy')->name('activity.destroy');
    });

    //新人优惠券礼包
    Route::group(['prefix' => 'issue'], function () {
        Route::any('index', 'IssueController@index')->name('issue.index');
        Route::post('table', 'IssueController@table')->name('issue.table');
        Route::post('activity_table', 'IssueController@activity_table')->name('issue.activity_table');
        Route::post('activity_interim_table', 'IssueController@activity_interim_table')->name('issue.activity_interim_table');
        Route::post('activity_table', 'IssueController@activity_table')->name('issue.activity_table');
        Route::get('edit/{id}', 'IssueController@edit')->name('issue.edit');
        Route::put('edit/{id}', 'IssueController@update')->name('issue.update');
        Route::any('add', 'IssueController@create')->name('issue.add');
        Route::post('store', 'IssueController@store')->name('issue.store');
        Route::post('activity_store', 'IssueController@activity_store')->name('issue.activity_store');
        Route::post('upstatus/{id?}', 'IssueController@upstatus')->name('issue.upstatus');
        Route::delete('destroy/{id?}', 'IssueController@destroy')->name('issue.destroy');
        Route::get('_form', function () {
            return view('Admin.issue._form');
        })->name('issue.form');
    });

    include 'web-3.php';//上传部分路由
});
    include 'ajax.php';//ajax请求数据路由
